package _interview100;

/**
 * 75. 颜色分类
 */
public class No75 {
    public void sortColors(int[] nums) {
        int left = 0, right = nums.length - 1;

        for (int i = 0; i <= right; ) {
            int temp = nums[i];
            if (temp == 0) {
                nums[i] = nums[left];
                nums[left++] = temp;
            } else if (temp == 2) {
                nums[i] = nums[right];
                nums[right--] = temp;
            } else {
                i++;
            }
            i = Math.max(i, left);
        }
    }
}
